package com.quantgroup.data.saastest.config.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author yangjinhua
 */
@Data
@NoArgsConstructor
public class TenantDbData implements Serializable {
    private static final long serialVersionUID = 2223275453947859214L;

    /**
     * 数据源唯一标识
     */
    private String dbKey;
    /**
     * 数据库url（ip:port）
     */
    private String dbUrl;
    /**
     * 库名
     */
    private String dbName;
    /**
     * 库用户名
     */
    private String dbUsername;
    /**
     * 库密码
     */
    private String dbPassword;
    /**
     * 租户Id
     */
    private Integer tid;
    /**
     *  mysql/mongo
     */
    private String dbType;

    public TenantDbData(String dbName, String dbUrl, String dbUsername, String dbPassword, String dbKey) {
        this.dbType = "mysql";
        this.dbName = dbName;
        this.dbUrl = dbUrl;
        this.dbUsername = dbUsername;
        this.dbPassword = dbPassword;
        this.dbKey = dbKey;
    }

    public String getDbUrl() {
        String format = "jdbc:mysql://%s/%s";
        return String.format(format, this.dbUrl, this.dbName);
    }
}
